let markid = getUrlString('markid');
let isApp = getUrlString('isApp');
let page = -1,totalSize = 0,type=getUrlString('type');
$(function () {
    let mRefresh = new MiniRefresh({
        container: '#mrefresh', //这里是插件的容器ID
        down: {
            isAuto: false,
            callback: function () {
                // 下拉后的回调事件 ，你可以在这里执行你的后台请求数据函数，达到刷新数据的作用
                $('#redList').empty();//清空容器
                totalSize = 0;
                page = -1;
                mRefresh.endDownLoading();
            }
        }
        ,
        up: {
            isAuto: true,
            callback: function () {
                // 向上拉后的回调事件
                page += 1;
                redList(page,type);
            }
        }
    });

    function redList (cuppage,type) {
        let data = {
            'markid':markid,
            'type':type,
            'page':cuppage
        };
        getData('post','/niu/apiv4/fahuo_couponlist.php',data,function (data) {
            console.log(data);
            let append = '';
            $('.cupTypeNum').html(data.num+'张');
            $(data.info).each(function () {
                append += '<li>' +
                    '                    <div>'+this.name+'</div>' +
                    '                    <div class="time">有效期至 '+this.end_time+'</div>' +
                    '                    <div class="info">'+this.intro+'</div>' ;

                    if (this.type === "0" || this.type === "2"){
                        if (isApp !== '1' && isApp !== '2'){
                            append +=  '                    <div onclick="useClick()" class="use">去使用</div>' ;
                        }
                    }else if (this.type === "3" || this.type === "5"){
                        if (isApp !== '1' && isApp !== '2') {
                            append += '                    <div onclick="gotoDanji()" class="gotoDanji">去使用</div>';
                        }
                    } else if (this.type === "7"){
                        if (isApp !== '2') {
                            append += '                    <div onclick="gotocupDanji()" class="gotocupDanji useCommon">去使用</div>';
                        }
                    } else {
                        if (isApp !== '1'&& isApp !== '2') {
                            append += '                    <div onclick="renewal()" class="renewal">去使用</div>';
                        }
                    }

                    append += '                </li>'
            });
            $('#redList').append(append);
            //总条数
            totalSize = totalSize + 10;
            if (totalSize > data.num)
                mRefresh.endUpLoading(true);
            else{
                mRefresh.endUpLoading(false);
            }
        })
    }

});

function renewal() {
    window.location.href = 'dancool://web='+urlView+'my/myEggPoolRenewal.html?type=0'
}

function gotoDanji() {
    window.location.href = 'dancool://web='+urlView+'danji/danji.html?danjiid=12526&is_parent=1'
}

function gotocupDanji () {
    if (isApp === '1'|| isApp === '2'){
        window.location.href = urlView+'danji/cupDanji.html?danjiid=12945&markid='+markid+'&isApp='+isApp
    } else {
        window.location.href = 'dancool://web='+urlView+'danji/cupDanji.html?danjiid=12945'
    }
}

function useClick (){
    window.location.href = 'dancool://web='+urlView+'my/myEggPoolShipments.html?type=0'
}
